package com.example.springbootsecurity.service;

import com.example.springbootsecurity.entity.LoginUser;
import com.example.springbootsecurity.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

/**
 * 用户验证处理
 *
 * @author ruoyi
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    private static final Logger log = LoggerFactory.getLogger(UserDetailsServiceImpl.class);

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //这里假装查询出用户信息
        User user = new User().setName("admin").setPassword("e10adc3949ba59abbe56e057f20f883e");
        return createLoginUser(user);
    }

    public UserDetails createLoginUser(User user) {
        //permissionService.getMenuPermission(user)
        //这里假装查出来用户权限信息
        Set<String> permissions = new HashSet<>();
        permissions.add("system:menu:query");
        return new LoginUser(user,permissions );
    }
}
